package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.menu.*;
import com.mes.cloud.api.dto.response.menu.SysMenuDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wxm
 * @version 2019-07-30 13:55:22
 * @email xiaomin.wu1@pactera.com
 */
@Api(tags = "系统菜单", value = "系统菜单接口")
@RestController
@RequestMapping(value = "/sysMenu")
public class SysMenuController {

    private SysMenuService sysMenuService;

    @Autowired
    public SysMenuController(SysMenuService sysMenuService) {
        this.sysMenuService = sysMenuService;
    }

    /**
     * 系统菜单左边列表
     *
     * @param menuPageListRequest
     * @return JsonResult<CommPager<SysMenuDto>>
     */
    @ApiOperation(value = "系统菜单分页查询", notes = "系统菜单分页查询")
    @PostMapping(value = "/pageList")
    public JsonResult<CommPager<SysMenuDto>> pageList(@Valid @RequestBody MenuPageListRequest menuPageListRequest) {
        JsonResult<CommPager<SysMenuDto>> pageList = sysMenuService.pageList(menuPageListRequest);
        return pageList;
    }


    /**
     * 系统菜单左边树
     *
     * @return JsonResult<List<SysMenuDto>>
     */
    @ApiOperation(value = "系统菜单查询所有", notes = "系统菜单查询所有")
    @PostMapping(value = "/allRejectButtonList")
    public JsonResult<List<SysMenuDto>> allRejectButtonList(@RequestBody AllRejectButtonListRequest allRejectButtonListRequest) {
        JsonResult<List<SysMenuDto>> list = sysMenuService.allRejectButtonList(allRejectButtonListRequest);
        return list;
    }

    /**
     * 获取菜单
     *
     * @return JsonResult<List<SysMenuDto>>
     */
    @ApiOperation(value = "获取菜单", notes = "获取菜单")
    @PostMapping(value = "/listByIds")
    public JsonResult<List<SysMenuDto>> listByIds(@Valid @RequestBody SysMenuListByIdsRequest sysMenuListByIdsRequest) {
        return sysMenuService.listByIds(sysMenuListByIdsRequest);
    }

    /**
     * 获取客户类型下的菜单
     *
     * @return JsonResult<List<SysMenuDto>>
     */
    @ApiOperation(value = "获取客户类型下的菜单", notes = "获取客户类型下的菜单")
    @PostMapping(value = "/listByCustomerType")
    public JsonResult<List<SysMenuDto>> listByCustomerType(@Valid @RequestBody SysMenuListByCustomerTypeRequest sysMenuListByCustomerTypeRequest) {
        return sysMenuService.listByCustomerType(sysMenuListByCustomerTypeRequest);
    }

    /**
     * 系统菜单新增
     *
     * @param sysMenuRequest
     * @return JsonResult
     */
    @ApiOperation(value = "系统菜单新增", notes = "系统菜单新增")
    @PostMapping(value = "/add")
    public JsonResult<SysMenuDto> add(@Valid @RequestBody SysMenuRequest sysMenuRequest) {
        return sysMenuService.insert(sysMenuRequest);
    }

    /**
     * 系统菜单修改
     *
     * @param sysMenuRequest
     * @return JsonResult
     */
    @ApiOperation(value = "系统菜单修改", notes = "系统菜单修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody SysMenuRequest sysMenuRequest) {
        return sysMenuService.update(sysMenuRequest);
    }

    /**
     * 批量删除系统菜单
     *
     * @param sysMenuDatchDeleteRequest
     * @return JsonResult
     */
    @ApiOperation(value = "批量删除系统菜单", notes = "批量删除系统菜单")
    @PostMapping(value = "/batchDelete")
    public JsonResult batchDelete(@Valid @RequestBody SysMenuDatchDeleteRequest sysMenuDatchDeleteRequest) {
        return sysMenuService.batchDelete(sysMenuDatchDeleteRequest);
    }

    /**
     * 系统菜单查看详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "系统菜单查看详情", notes = "系统菜单查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "系统菜单主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<SysMenuDto> get(@NotEmpty(message = "id不能为空") @PathVariable String id) {
        return sysMenuService.get(id);
    }

    /**
     * 系统菜单禁用启用
     *
     * @param id
     * @param enableFlag
     * @return
     */
    @ApiOperation(value = "系统菜单禁用启用", notes = "系统菜单禁用启用")
    @GetMapping(value = "/updateEnableFlag/{id}/{enableFlag}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true),
            @ApiImplicitParam(name = "enableFlag", value = "状态", required = true),
    })
    public JsonResult updateEnableFlag(@NotEmpty(message = "id不能为空") @PathVariable String id, @NotEmpty(message = "enableFlag不能为空") @PathVariable String enableFlag) {
        return sysMenuService.updateEnableFlag(id, enableFlag);
    }

    @PostMapping(value = "/getSubMenuList")
    public JsonResult<List<SysMenuDto>> getSubMenuList(@Valid @RequestBody SubMenuRequest subMenuRequest) {
        return sysMenuService.getSubMenuList(subMenuRequest);
    }


    @GetMapping(value = "/updateParentGroup")
    public JsonResult updateParentGroup() {
        return sysMenuService.updateParentGroup();
    }


    @GetMapping(value = "/updateCode")
    public JsonResult updateCode() {
        return sysMenuService.updateCode();
    }

    @PostMapping(value = "/getSubMenuListByUrl")
    public JsonResult<List<SysMenuDto>> getSubMenuListByUrl(@Valid @RequestBody SubMenuByUrlRequest subMenuByUrlRequest) {
        return sysMenuService.getSubMenuListByUrl(subMenuByUrlRequest);
    }

    /**
     * 系统菜单左边列表
     *
     * @param menuListRequest
     * @return List<CommPager<SysMenuDto>>
     */
    @ApiOperation(value = "系统菜单查询", notes = "系统菜单查询")
    @PostMapping(value = "/findList")
    public JsonResult<List<SysMenuDto>> findList(@Valid @RequestBody MenuListRequest menuListRequest) {
        JsonResult<List<SysMenuDto>> findList = sysMenuService.findList(menuListRequest);
        return findList;
    }

    /**
     * 获取渠道属性下所有的菜单
     *
     * @param channelAttributeSubListRequest
     * @return List<CommPager<SysMenuDto>>
     */
    @ApiOperation(value = "获取渠道属性下所有的菜单", notes = "获取渠道属性下所有的菜单")
    @PostMapping(value = "/channelAttributeSubList")
    public JsonResult<List<SysMenuDto>> channelAttributeSubList(@Valid @RequestBody ChannelAttributeSubListRequest channelAttributeSubListRequest) {
        return sysMenuService.channelAttributeSubList(channelAttributeSubListRequest);
    }

    @PostMapping(value = "/getSNSubMenuList")
    public JsonResult<List<SysMenuDto>> getSNSubMenuList(@Valid @RequestBody SNSubMenuRequest sNsubMenuRequest) {
        return sysMenuService.getSNSubMenuList(sNsubMenuRequest);
    }

}
